package com.ts.proj.service.impl;

import com.ts.base.service.impl.CommonServiceImpl;
import com.ts.proj.entity.ProjectMeetingEntity;
import com.ts.proj.repository.ProjectMeetingRepository;
import com.ts.proj.service.ProjectMeetingService;
import com.ts.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class ProjectMeetingServiceImpl extends CommonServiceImpl<ProjectMeetingEntity> implements ProjectMeetingService {

    @Autowired
    private ProjectMeetingRepository projectMeetingRepository;

    @Override
    public List<ProjectMeetingEntity> findAll(PageData pageData, Integer start, Integer length) {
        Specification<ProjectMeetingEntity> sp = this.getSpecification(pageData,ProjectMeetingEntity.class);
        Sort sort = new Sort(Sort.Direction.ASC,"id");
        Pageable pageable = new PageRequest(start, length, sort);
        return projectMeetingRepository.findAll(sp,pageable).getContent();
    }

    @Override
    public long count(PageData pageData) {
        Specification<ProjectMeetingEntity> sp = this.getSpecification(pageData,ProjectMeetingEntity.class);
        return projectMeetingRepository.count(sp);
    }

    @Override
    public boolean deleteByIds(Iterable<ProjectMeetingEntity> iterable) {
        projectMeetingRepository.deleteInBatch(iterable);
        return false;
    }

    @Override
    public List<ProjectMeetingEntity> saveAll(List<ProjectMeetingEntity> list) {
        return projectMeetingRepository.saveAll(list);
    }

    @Override
    public List<ProjectMeetingEntity> findAllById(Integer[] integers) {
        List<ProjectMeetingEntity> list = projectMeetingRepository.findAllById(Arrays.asList(integers));
        if(list.size()==0){
            ProjectMeetingEntity entity = new ProjectMeetingEntity();
            list.add(entity);
        }
        return list;
    }

    @Override
    public boolean deleteAll() {
        projectMeetingRepository.deleteAll();
        return false;
    }
}
